package com.blog.cmrpersonalblog.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 通知统计实体类
 */
@Data
@TableName("notification_stats")
public class NotificationStats {

    /**
     * 统计ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户ID
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 未读粉丝通知数
     */
    @TableField("unread_follow_count")
    private Integer unreadFollowCount;

    /**
     * 未读点赞通知数
     */
    @TableField("unread_like_count")
    private Integer unreadLikeCount;

    /**
     * 未读收藏通知数
     */
    @TableField("unread_collect_count")
    private Integer unreadCollectCount;

    /**
     * 未读评论通知数
     */
    @TableField("unread_comment_count")
    private Integer unreadCommentCount;

    /**
     * 未读回复通知数
     */
    @TableField("unread_reply_count")
    private Integer unreadReplyCount;

    /**
     * 未读系统通知数
     */
    @TableField("unread_system_count")
    private Integer unreadSystemCount;

    /**
     * 未读公告数
     */
    @TableField("unread_announcement_count")
    private Integer unreadAnnouncementCount;

    /**
     * 总未读通知数
     */
    @TableField("total_unread_count")
    private Integer totalUnreadCount;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 判断是否有未读通知
     */
    public boolean hasUnread() {
        return totalUnreadCount != null && totalUnreadCount > 0;
    }

    /**
     * 获取指定类型的未读数量
     */
    public Integer getUnreadCountByType(String type) {
        switch (type) {
            case Notification.TYPE_FOLLOW:
                return unreadFollowCount;
            case Notification.TYPE_LIKE:
                return unreadLikeCount;
            case Notification.TYPE_COLLECT:
                return unreadCollectCount;
            case Notification.TYPE_COMMENT:
                return unreadCommentCount;
            case Notification.TYPE_REPLY:
                return unreadReplyCount;
            case Notification.TYPE_SYSTEM:
                return unreadSystemCount;
            default:
                return 0;
        }
    }
}

